const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

//（方法，请求地址，数据，成功回调）
const http = (method,httpUrl,requestData,SuccessFunction)=>{
  wx.request({
    url: httpUrl,
    method:method,
    data: requestData,
    success: function(res){
      SuccessFunction(res)
    },
    fail:function(){
      wx.showToast({
        title: '请求失败',
        icon: 'error',
        duration: 2000
      })
    }
  })
}

module.exports = {
  formatTime,
  http
}
